using System;
using System.Collections.Generic;
using System.Linq;
namespace TTSoft.MyApp.Repositories
{
	#region using
	using TTSoft.MyApp.Models;
	#endregion
	public class DocGiaRepository
	{
		public static List<DocGia> SelectAll()
		{
			return DataContext.Instance.DocGia.ToList();
		}

		public static DocGia SelectByID(int iddocgia)
		{
			return DataContext.Instance.DocGia.FirstOrDefault(item => item.IDDocGia == iddocgia );
		}

		public static bool Insert(DocGia obj)
		{
			try
			{
				DataContext.Instance.DocGia.AddObject(obj);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Delete(int iddocgia)
		{
			try
			{
				var delitem = DataContext.Instance.DocGia.FirstOrDefault(item => item.IDDocGia == iddocgia );
				DataContext.Instance.DocGia.DeleteObject(delitem);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Save()
		{
			try
			{
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static List<DocGia> RetrieveByID(int iddocgia)
		{
			return (from item in DataContext.Instance.DocGia where  item.IDDocGia == iddocgia  select item).ToList();
		}

	}
}